wait_time = 0
wait_event = 1

class Component:
	def __init__(self,name,parent=None):
		self.name=name
		if isinstance(parent, Simulator):
			self.sim=parent
		elif isinstance(parent, Component):
			self.sim=parent.sim
			self.parent=parent
		sim.register_component(self)
	
	def start(self,t):
		return self.sim.register_comp_thread(self,t)
	
	def kill_thread(self,t):
		self.sim.kill_thread_by_handle(t)

	
	def on_event(self,ev,f):
		ev.add_callback(f)

	def get_childred(self):
		children = []
		for c,p in self.sim.components.iteritems():
			if p==self:
				childred.append(c)
		return children

	def has_children(self):
		return self in self.sim.components.values()
	
	def run():
		pass

def Simulate(comp):
	comp.sim.simulate()
	

